﻿//
	var imgUrlArray=new Array();
	var imageUrl;
	var count=0; 	
	var Atitle,Acontent;
	$(document).ready(function()
		{
	
		
	KindEditor.ready(function(K) 
	{
		// 创建编辑框
		var editor = K.create('textarea[name=content]', 
		{
			resizeType : 1,
			allowPreviewEmoticons : false,
			allowImageUpload : true,
			afterUpload : function(data){
				imgUrlArray[count] = data;
				count++;
			},
			items :
			[
				"source", "|", "undo", "redo", "|", "preview", "print", "template", "code", "cut", "copy", "paste",
		        "plainpaste", "wordpaste", "|", "justifyleft", "justifycenter", "justifyright",
		        "justifyfull", "insertorderedlist", "insertunorderedlist", "indent", "outdent", "subscript",
		        "superscript", "clearhtml", "quickformat", "selectall", "|", "fullscreen", "/",
		        "formatblock", "fontname", "fontsize", "|", "forecolor", "hilitecolor", "bold",
		        "italic", "underline", "strikethrough", "lineheight", "removeformat", "|", "image", "multiimage",
		        "flash", "media", "insertfile", "table", "hr", "emoticons", "baidumap", "pagebreak",
		        "anchor", "link", "unlink", "|", "about"
			]
		});

		/*初始化编辑框
		editor.html();*/
	
	
			// 博文提交按钮
			$("input[name=putArticle]").click(function()
			{
				Acontent= editor.html();
				if(imgUrlArray.length!=0)
				{
					imageUrl=imgUrlArray[Math.floor(Math.random()*imgUrlArray.length)];
				}else
				{
					imageUrl=" ";
				}
				var title = $("input[name=title]").val();
				//随机图片路径
				$("input[name=imgUrl]").val(imageUrl);
				var sortId=$(".tag").val();
				if(sortId.length==0)
				{
					sortId = 0;
				}
				//Atitle=$("input[name=title]").val();
				$.ajax({
					url:"w/index",
					type:"post",
					dataType:"text",
					data:{"blog":Acontent,"imgUrl":imageUrl,"sortId":sortId,"title":title},
					success:function(msg)
					{

					}
				});
			});
	});//end KindEditor.ready
		
	// 添加分类按钮
	$("input[name=createSort]").click(function()
	{
		var articleSort=$("input[name=sort]").val();

		if(articleSort!="")
		{
			$.ajax({
				url : "w/CreateSort",
				type : "post",
				dataType : "text",
				data : {"articleSort":articleSort},
				success : function(data)
				{
						if(data==true)
						{
							selectTag();
							alert("success");
						}else{
							alert("创建失败");
						}
				}
			});
		}else{
			alert("not null");
		}
		
	});

	// 刷新分类标签按钮
	$("#tagList").click(function()
	{	
		selectTag();
	});//end click

	// 搜索分类标签		


});//end ready

function selectTag()
{
	$.ajax({
			url : "w/SelectTag",
			dataType : "json",
			data:{"tag":"true"},
			type : "post",
			success : function(data)
			{	
				alert(data);
				//var obj = eval("("+data+")");
				$(".tag").empty();
				$.each(data,function(k,v)
				{
					$(".tag").append("<option value="+v.article_sort_id+">"+v.sort_name+"</option>");
				});
				$(".tag").append("<option value='0'>以后分类</option>");
			}
		});
}

		